package com.ruoyi.framework.security.context

import com.ruoyi.common.core.text.Convert.toStr
import org.springframework.web.context.request.RequestAttributes
import org.springframework.web.context.request.RequestContextHolder

/**
 * 权限信息
 *
 * @author ruoyi
 */
object PermissionContextHolder {
    private const val PERMISSION_CONTEXT_ATTRIBUTES = "PERMISSION_CONTEXT"
    @JvmStatic
    var context: String?
        get() = toStr(RequestContextHolder.currentRequestAttributes().getAttribute(PERMISSION_CONTEXT_ATTRIBUTES,
                RequestAttributes.SCOPE_REQUEST))
        set(permission) {
            permission?.let {
                RequestContextHolder.currentRequestAttributes().setAttribute(PERMISSION_CONTEXT_ATTRIBUTES, it,
                    RequestAttributes.SCOPE_REQUEST)
            }
        }
}
